import { quickSort } from "./03_泛型函数";
import { isChinese, sortChinese } from "./04_泛型函数重载";
let chineseArr = ["武汉", "石家庄", "郑州", "太原", "济南", "沈阳", "大连"];

// 字符串自排序
export function strSelfSort(str: string) {
  const strArr = str.split("");
  const sortSortArr = quickSort(strArr);
  return sortSortArr.join("");
}

export function sort<T>(data: T): Array<any>;
export function sort<T>(data: T): string | undefined;

export function sort<T>(data: T): Array<any> | string | undefined {
  if (data instanceof Array) {
    // 数组
    if (isChinese(data)) {
      // 数组中包含中文
      return sortChinese(data);
    } else {
      // 数组中不包含中文
      return quickSort(data);
    }
  } else if (typeof data === "string") {
    // 单纯的字符串
    return strSelfSort(data);
  }
}

console.log(sort(chineseArr), sort("adfasfdas"));

export {};
